﻿/*----------------------------------------------------------------
 * 
 * 版权所有：Copyright (C) 2013
 * 
 * 文件名：ILoadAll.cs
 * 文件功能描述：
 * 
 * 
 * 作 者：zhangq
 * 邮 箱：ifunnyface@outlook.com
 * 日 期：2013-01-07 16:54:47
 * 
 * 
 * 修改标识： Author
 * 修改描述： 相关描述
 * 
 * ---------------------------------------------------------------- */

using Common.Extensions.OrderBy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace IDataAccess
{

    /// <summary>
    /// 
    /// </summary>
    public interface ILoadAll<T> where T : class
    {


        /// <summary>
        /// 获取总数
        /// </summary>
        /// <param name="where">条件</param>
        /// <returns>记录总数</returns>
        int LoadCount(Expression<Func<T, bool>> where);



        /// <summary>
        /// 根据条件分页获得记录
        /// </summary>
        /// <param name="where">条件</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页大小</param>
        /// <param name="orderByExpressions"></param>
        /// <returns>记录列表</returns>
        IList<T> LoadAll(Expression<Func<T, bool>> where,
                        int pageIndex, 
                        int pageSize, 
                        params IOrderByExpression<T>[] orderByExpressions);

        ///// <summary>
        ///// 根据条件分页获得记录
        ///// </summary>
        ///// <param name="where">条件</param>
        ///// <param name="pageIndex">当前页码</param>
        ///// <param name="pageSize">每页大小</param>
        ///// <param name="totalRecord">总记录数</param>
        ///// <param name="orderByExpressions">排序字段</param>
        ///// <returns>记录列表</returns>
        //public IList<ArticlePartitionInfo> LoadAll(Expression<Func<ArticlePartitionInfo, bool>> where,
        //                         int pageIndex,
        //                         int pageSize,
        //                         out int totalRecord,
        //                         params IOrderByExpression<T>[] orderByExpressions)
        //{
        //    using (var db = new EFDBContext())
        //    {
        //        var list = db.ArticlePartitions.Where(where);
        //        totalRecord = list.Count();
        //        if (totalRecord <= 0)
        //        {
        //            return new List<ArticlePartitionInfo>();
        //        }

        //        list = list.OrderBy(new OrderByExpression<ArticlePartitionInfo, string>(a => a.Name),
        //                            new OrderByExpression<ArticlePartitionInfo, int>(a => a.PartitionId));
        //        list = list.Skip((pageIndex - 1) * pageSize).Take(pageSize);

        //        //调试输出SQL，注意query不能ToList()，否则就不是IQueryable了 
        //        Debug.WriteLine(list.ToString());

        //        return list.ToList();
        //    }
        //}

    }

}